<template>
	<view>
		<u-card :head-style="headStyle1">

			<view class="car" slot="body">
				<view class="image">
					<image src="/static/images/car.png" mode="widthFix"></image>
				</view>
				<view class="content">
					<view class="title">
						<text style="font-size: 32rpx;">{{car_detail.car_num}}</text>
						<text></text>
					</view>

				</view>
				<view class="car_type">
					<text>{{car_detail.brand}}</text>
					<text style="margin-left: 14rpx;">{{car_detail.model}}</text>
				</view>

			</view>

		</u-card>

		<u-card :head-style="headStyle" :body-style="bodyStyle">
			<view class="tab_body" slot="head">
				<u-tabs :list="list" :is-scroll="false" bar-height="6" bar-width="120" active-color="#eb3626"
					:current="current" @change="change"></u-tabs>
			</view>
			<view class="" slot="body">
				<view class="tba_content" v-if="current==0">
					<view class="item" v-for="(item,index) in info_list" @click="jump_car_detail(item.id,item.car_id)" >
						<view class="item-flex">
							<view class="">
								<text class="tip">保</text>
								<text class="date">
									{{item.appointment_time}}
								</text>
							</view>
							<view class="">
								<u-icon class="pay" v-if="item.pay_status == 1" name="arrow-right" label="已付款" label-pos="left" ></u-icon>
								<u-icon class="pay" v-if="item.pay_status == 0" name="arrow-right" label="待付款" label-pos="left" ></u-icon>
							</view>
						</view>

						<view class="item_detail">
							<view class="mileage">
								金额：￥{{item.price}}
							</view>
							<view class="money">
								里程： {{item.mileage}} KM
							</view>
							<view class="project">
								项目： {{item.goods_example}}
							</view>
						</view>
					</view>

			<view class="no_record" v-if="info_list.length==0">
				暂无记录
			</view>
				</view>
				<view class="tba_content" v-if="current==1">
					<view class="item" v-for="(item,index) in info_list"  @click="jump_car_detail(item.id,item.car_id)">
						<view class="item-flex">
							<view class="">
								<text class="tip maintain">维</text>
								<text class="date">
									{{item.appointment_time}}
								</text>
							</view>
							<view class="">
								<u-icon class="pay" v-if="item.pay_status == 1" name="arrow-right" label="已付款" label-pos="left" ></u-icon>
								<u-icon class="pay" v-if="item.pay_status == 0" name="arrow-right" label="待付款" label-pos="left" ></u-icon>
							</view>
						</view>

						<view class="item_detail">
							<view class="mileage">
								金额：￥{{item.price}}
							</view>
							<view class="money">
								里程： {{item.mileage}} KM
							</view>
							<view class="project">
								项目： {{item.goods_example}}
							</view>
						</view>
					</view>


				<view class="no_record" v-if="info_list.length==0">
					暂无记录
				</view>
				</view>
			</view>

		</u-card>


	</view>
</template>

<script>
	export default {
		data() {
			return {
				headStyle: {
					paddingBottom: 0
				},
				headStyle1: {
					paddingBottom: 0,
					paddingTop: 0
				},
				bodyStyle: {
					padding: "10rpx 0"
				},
				list: [{
					name: '保养信息'
				}, {
					name: '维修记录'
				}],
				current: 0,
				car_detail: {},
				id : 0,
				info_list:{}
			}
		},
		onLoad: function(options) {
			console.log(options);
			this.id = options.id;
			this.getCarInfo(options.id);
			this.getCarDetail(options.id);
		},
		methods: {
			jump_car_detail(id,car_id){
				uni.navigateTo({
					url: `/pages/car_detail/car_detail?id=${id}&car_id=${car_id}`
				});
			},
			change(index) {
				this.current = index;
				let type = 1;
				if(index == 1){
					type =2
				}
				this.getCarInfo(this.id,type);
			},
			getCarDetail(car_id) {
				this.$u.api.getCarDetail({
					id: car_id
				}).then(res => {
					console.log(res, 'getCarDetail');
					if (res.status == 200) {
						this.car_detail = res.data;

					}
				})
			},
			getCarInfo(id,type = 3) {
				this.$u.api.getCarInfo({
					id,
					type
				}).then(res => {
					console.log(res, 'getCarInfo');
					if (res.status == 200) {
						this.info_list = res.data;
					}
				})
			}
		}
	}
</script>

<style lang="scss">
	page {
		background-color: #f1f1f1;
	}

	.car {
		display: flex;
		flex-direction: column;
		align-items: center;

		.image {
			width: 80rpx;
			height: 80rpx;
			border-radius: 50%;

			image {
				width: 100%;
			}
		}

		.content {
			color: #000;

			.title {
				font-size: 28rpx;
				font-weight: 700;
			}
		}
	}

	.tab_body {
		padding: 0px 10rpx;
	}

	.tba_content {
		.item {
			padding: 18rpx 22rpx;
			border-bottom: 2rpx solid #e3e3e3;

			.item-flex {
				display: flex;
				justify-content: space-between;

				.tip {
					font-size: 20rpx;
					width: 150rpx;
					height: 150rpx;
					border-radius: 50%;
					padding: 6rpx 10rpx;
					background-color: #1dd18f;
					margin-right: 10rpx;
					color: #fff;
				}

				.maintain {
					background-color: #eb3626;
				}

				.date {
					font-size: 700;
					color: #000;
				}
			}

			.item_detail {
				margin-left: 50rpx;
				font-size: 26rpx;
				color: #8c8c8c;
				line-height: 44rpx;

				.project {

					overflow: hidden;
					white-space: nowrap;
					text-overflow: ellipsis;
				}
			}

		}

		.item:last-child {
			border-bottom: 0;
		}
	}
	.no_record{
		padding: 20rpx 16rpx;
	}
</style>
